<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
	<head>
		<title>公会列表</title>
		<base href="<%=basePath%>" />
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<meta name="apple-mobile-web-app-title" content="Amaze UI" />
		<link rel="stylesheet" href="layui/css/layui.css" media="all"> <!-- 适应所有设备 -->
		<style type="text/css">
		</style>
	</head>
	<% String nowDay = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); %>
	<body>
	
	    <form class="layui-form" onsubmit='return false'>
	      <br/>
	      <div class="layui-form-item">
			<div class="layui-input-inline">
				<select name="DispalyLevel" id="DispalyLevel" lay-filter="DispalyLevel">
					<option value="-1">显示全部</option>
					<option value="0">正常</option>
					<option value="1">已屏蔽</option>
					<option value="2">已上榜</option>
					<option value="3">已置顶</option>
				</select>
			</div>
			<div class="layui-inline">
				<div class="layui-input-inline">
					<button class="layui-btn layui-btn-normal" data-type="reload" id="SelectOrder" lay-filter="SelectOrder">搜索</button>
				</div>
			</div>
			
	      </div>
	    
	    <table class="layui-hide" id="Guild" lay-filter="Guild"></table>
	    </form>
	    <script type="text/html" id="modify">
          <a class="layui-btn layui-btn-xs " lay-event="see">仓库</a>
          <a class="layui-btn layui-btn-xs" lay-event="journal">日志</a>
          <a class="layui-btn layui-btn-xs" lay-event="del">解散</a>
        </script>
        
        <script type="text/html" id="DisplayLevel">
            {{#  if(d.DisplayLevel == 0){ }}
                <span class="layui-badge layui-bg-green">正常</span>
            {{#  } else if(d.DisplayLevel == 1){ }}
                <span class="layui-badge layui-bg-black">已屏蔽</span>
            {{#  } else if(d.DisplayLevel == 2){ }}
                <span class="layui-badge">已上榜</span>
            {{#  } else if(d.DisplayLevel == 3){ }}
                <span class="layui-badge layui-bg-blue">已置顶</span>
            {{#  } else { }}
                <span class="layui-badge">显示错误</span>
            {{#  } }}
        </script>
	    
	    <script src="js/jquery.min.js"></script>
		<script src="layui/layui.js"></script>
		<script src="js/common/monitor_back.js"></script>

		<script>
		    layui.use(['layer','form','table'],function(){
		    	var layer = layui.layer,
		    	    form  = layui.form,
		    	    table = layui.table;
		    	
		    	layer.config({
					extend: 'MySkin/style.css'
				});
		    	table.render({
		    		elem:'#Guild',
		    		url:'guild/List',
		    		method:'post',
		    		title:'渠道',
		    		skin: 'row',
		    		even: true,
		    		page : true,//分页
		    		autoSort: false,
		    		id:'AllTable',
		    		request:{
						pageName:'PageIndex',
						limitName:'PageCount'
					},
					where:{
						DisplayType:$("#DispalyLevel").val()
					},
		    		cols:[[
		    			{field:'GuildId',title:'公会ID ',style:'color:#d71345',width:100,sort:true},
		    			{field:'GuildName',title:'公会名称',style:'color:#f47920',width:120},
		    			{field:'GuildLevel',title:'公会等级',style:'color:#f05b72',width:110,sort:true},
		    			{field:'GuildMemberCount',title:'公会人数',style:'color:#1d953f',width:110,sort:true},
		    			{field:'GuildRedpacketPool',title:'公会红包实时额度',style:'color:#009ad6',sort:true},
		    			{field:'UserId',title:'会长ID',style:'color:#5c7a29'},
		    			{field:'Nickname',title:'会长昵称',style:'color:#ed1941'},
		    			{field:'GuildMembersCost',title:'公会玩家金币总消耗',style:'color:#009ad6'},
		    			{field:'GuildWelfare',title:'会长福利 实时额度',style:'color:#009ad6',sort:true},
		    			{field:'CreateTime',title:'公会创建时间',style:'color:#69541b',sort:true},
		    			{field:'DisplayLevel',title:'公会级别',width:110,sort:true,templet: '#DisplayLevel',event: 'ChangeState', style:'cursor: pointer;'},
		    			{fixed:'right',title:'操作 ',toolbar: '#modify'},
		    			]],
						response : {
							statusCode : 200
						//重新规定成功的状态码为 200，table 组件默认为 0
						},
						parseData : function(res) { //将原始数据解析成 table 组件所规定的数据
							return {
								"code" : res.status, //解析接口状态
								"msg" : res.message, //解析提示文本
								"count" : res.count, //解析数据长度
								"data" : res.data
							//解析数据列表
							};
						}
		    	});
		    	
		    	//监听行工具事件
		    	table.on('tool(Guild)',function(obj){
					if (history.state == null){
						pushHistory();
					}
		    		var data = obj.data,
		    		layEvent = obj.event;
			        var guildId = data.GuildId;
			        var displayLevel  = data.DisplayLevel;
		    		if(layEvent === 'see'){
			    		var index = layer.open({
			    			type:2,
			    			shadeClose:true,
			    			shade:0.5,
			    			area:['100%', '100%'],
			    			title:'查看仓库',
			    			skin : 'layer-ext-yourskin',
			    			content:'guild/openwarehouse',
			    			success:function(layero,index){
			    				var body = layer.getChildFrame("body", index);
			    				body.find("#guildInformation").val(guildId);
			    			},
			    			error:function(){},
							cancel:function () {
								window.history.back();
							}
			    		});
		    		}else if(layEvent === 'del'){
		    			layer.confirm('确定解散公会么?',{
		    				btn:['确定','取消']
		    			},function(){
		    				$.ajax({
			    				type:"POST",
			    			    url:'guild/dissolution',
			    			    async: true,
			    			    data:{
			    			    	ID:guildId
			    			    },
			    			    success:function(resp){
			    			    	if(resp == null || resp == ""){
			    			    	    layer.msg("解散成功！！！",{icon:1});
			    			    	    setTimeout(function(){
			    			    	        layui.table.reload('AllTable',{});
			    			    	    },1000);
			    			    	}else{
			    			    		layer.msg(resp,{icon:2});
			    			    	}
			    			    },error:function(){
			    			    	
			    			    },
								cancel:function () {
									window.history.back();
								}
			    			});
		    			},function(){
		    				
		    			});
		    			
		    		}else if(layEvent === 'journal'){
		    			var index = layer.open({
		    				type:2,
			    			shadeClose:true,
			    			shade:0.5,
			    			area:['100%', '100%'],
			    			title:'查看公会日志',
			    			skin : 'layer-ext-yourskin',
			    			content:'guild/openlistjournal',
			    			success:function(layero,index){
			    				var body = layer.getChildFrame("body", index);
			    				body.find("#guildId").val(guildId);
			    			},
			    			error:function(){},
							cancel:function () {
								window.history.back();
							}
			    		});
		    		}else if(obj.event === 'ChangeState'){
		    			var index = layer.open({
		    				type:2,
		    				shadeClose:true,
		    				shade:0.5,
		    				area:['500px','250px'],
		    				title:'修改公会状态',
		    				content:'guild/chanegstate',
		    				success:function(layero,index){
		    					var body = layer.getChildFrame("body",index);
		    					body.find("#guildId").val(guildId);
		    				},
							cancel:function () {
								window.history.back();
							}
		    			});
		    		}
		    	});
		    	
		    	//排序
				table.on('sort(Guild)',function(obj){
					table.reload('AllTable',{
						initSort:obj //记录初始排序，如果不设的话，将无法标记表头的 排序状态 
						,where:{
							FilterField:obj.field    //排序字段
							,FilterType:obj.type    //排序方式
						}
					});
				});
		    	
		    	//定时刷新数据
				setInterval(function(){
					table.reload('AllTable', {
						page: {
							curr: 1 //重新从第 1 页开始
						}
						//根据条件查询
						,
						where: {
							DisplayType:$("#DispalyLevel").val()
						}
					});
	              },300000);
		    	
				
				//根据条件查询表格数据重新加载
				var active = {
					reload: function() {
						//获取用户名
						//执行重载
						table.reload('AllTable', {
							page: {
								curr: 1 //重新从第 1 页开始
							}
							//根据条件查询
							,
							where: {
								DisplayType:$("#DispalyLevel").val()
							}
						});
						return false;
					}
				};
				//点击搜索按钮根据用户名称查询
				$('#SelectOrder').on('click',
					function() {
						var type = $(this).data('type');
						active[type] ? active[type].call(this) : '';
					});
		    	
		    });
		</script>
    </body>
</html>